package com.tim.util;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Version 1.0, 2021/5/17
 * @Author Tim
 */
public class FormatUtil {

    public static String toCsvFormat(String origin){
        if(StringUtils.isBlank(origin)){
            return origin;
        }
        return "\""+origin.replaceAll("\"", "\"\"")+"\"";

    }

    public static List<String> toCsvFormat(List<String> origins){
        if(CollectionUtils.isEmpty(origins)){
            return origins;
        }
        List<String> result = origins.stream()
                .map(FormatUtil::toCsvFormat)
                .collect(Collectors.toList());
        return result;

    }


}
